package com.doit.day01;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.HFileOutputFormat2;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


public class Test1 {
    public static void main(String[] args) throws Exception {
        System.setProperty("HADOOP_USER_NAME","root");

        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "linux01:2181,linux02:2181,linux03:2181");


        Job job = Job.getInstance(conf);

        //给主类的类名
        job.setJarByClass(Test1.class);

        //map类的类名
        job.setMapperClass(CreateHFileDemo.class);

        //map程序输出的类型
        job.setMapOutputKeyClass(ImmutableBytesWritable.class);
        job.setMapOutputValueClass(KeyValue.class);

        //设置reducetask的个数
        job.setNumReduceTasks(0);

        //设置hfile文件给哪一张表的具体信息
        Connection conn = ConnectionFactory.createConnection(conf);
        TableName tableName = TableName.valueOf("test:user_info1");
        Table table = conn.getTable(tableName);
        RegionLocator regionLocator = conn.getRegionLocator(tableName);
        HFileOutputFormat2.configureIncrementalLoad(job,table,regionLocator);

        //输出的类名
        job.setOutputFormatClass(HFileOutputFormat2.class);

        //输入的路径
        FileInputFormat.setInputPaths(job,new Path("D:\\develop\\ideaWorkSpace\\Study\\data\\hbase.txt"));
        //输出的路径
        FileOutputFormat.setOutputPath(job,new Path("D:\\a\\"));

        job.waitForCompletion(true);
    }
}
